package com.example.demo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : yuanchuan
 * @date : 2023-11-22 21:07
 * @team : 西南综合开发支持部
 * @copyright :
 **/
public class R {
    private static final long serialVersionUID = 1L;

    private int code;

    private String msg;

    private Object data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static R warn(String msg) {
        return new R(ResultEnum.WARN.getCode(),msg);
    }
    public static R wrong(String msg) {
        return new R(ResultEnum.WRONG.getCode(),msg);
    }
    public static R warn(String msg, Object data) {
        return new R(ResultEnum.WARN.getCode(), msg, data);
    }
    public static R warn(Object data) {
        return new R(ResultEnum.WARN.getCode(), ResultEnum.WARN.getMessage(), data);
    }
    public static R warn() {
        return new R(ResultEnum.WARN.getCode(), ResultEnum.WARN.getMessage());
    }
    public static R warn(int code, String msg, Object data) {
        return new R(code, msg, data);
    }

    public static R warn(int code, String msg) {
        return new R(code, msg);
    }



    public static R ok(String msg) {
        return new R(ResultEnum.SUCCESS.getCode(),msg);
    }

    public static R ok(String msg, Object data) {
        return new R(ResultEnum.SUCCESS.getCode(), msg, data);
    }
    public static R ok(Object data) {
        return new R(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), data);
    }
    public static R ok() {
        return new R(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage());
    }
    public static R ok(int code, String msg, Object data) {
        return new R(code, msg, data);
    }

    public static R ok(int code, String msg) {
        return new R(code, msg);
    }

    public static R error(String msg) {
        return new R(ResultEnum.ERROR.getCode(), msg);
    }
    public static R error() {
        return new R(ResultEnum.ERROR.getCode(), ResultEnum.ERROR.getMessage());
    }
    public static R error(ResultEnum re) {
        return new R(re.getCode(), re.getMessage());
    }



    public static R error(ResultEnum re,Object data) {
        return new R(re.getCode(), re.getMessage(),data);
    }

    public static R error(String msg, Object data) {
        return new R(ResultEnum.ERROR.getCode(), msg, data);
    }

    public static R error(int code, String msg) {
        return new R(code, msg);
    }


    private R(int code, String msg) {
        this.code = code;
        this.data = new HashMap<>();
        this.msg = msg;

    }
    private R(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static R ok(int code, String msg, Long count, List list){
        Map data = new HashMap();
        data.put("totalCount",count);
        data.put("list",list);
        return ok(code, msg, data);
    }
}
